package modules.majiang.effect
{
	import com.greensock.TweenLite;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.geom.Point;
	import flash.utils.setTimeout;
	
	import modules.GameDispatcher;
	import modules.majiang.MajiangEvent;
	import modules.majiang.data.TableDataModel;

	/**
	 * 飞本轮赌注到奖池动画数据
	 * @author xumin.xu
	 */
	public class ChipsToPotEffectData
	{
		/**
		 * 动画起始位置
		 **/
		public static var startPoints:Array = [];

		public var endPoint:Point = new Point(500, 270);

		private var tableDataModel:TableDataModel;

		public function ChipsToPotEffectData(tableDataModel:TableDataModel)
		{
			this.tableDataModel = tableDataModel;

		}

		private function get dispatcher():GameDispatcher
		{
			return GameDispatcher.instance;
		}

		/**
		 * 播放赌注飞往奖池动画
		 **/
		public function chipsToPot(chairList:Array):void
		{
			logger("播放赌注飞往奖池动画");

			for (var i:int = 1; i <= 6; i++)
			{
				if (chairList.indexOf(i) != -1)
				{
					var chairId:int = i;
					var position:int = tableDataModel.getPositionByChairId(chairId);

					var data:Object = {position: position};
					//获取牌
					dispatcher.dispatchEvent(new MajiangEvent(MajiangEvent.GET_FLY_CHIP, data));

					var chip:MovieClip = data.chip;
					if (chip)
					{
						chip.x = startPoints[position].x;
						chip.y = startPoints[position].y;
					}
					//使用特效类
					var tweenObj:Object = {x: endPoint.x, y: endPoint.y};
					tweenObj.onStart = function(disO:DisplayObject):void
					{
						disO && (disO.visible = true);
					};
					tweenObj.onStartParams = [chip];
					tweenObj.onComplete = function(disO:DisplayObject):void
					{
						disO && (disO.visible = false);
					};
					tweenObj.onCompleteParams = [chip];

					TweenLite.to(chip, 0.8, tweenObj);

					setTimeout(function():void
					{
						tableDataModel.bonusPotsData.updateView();
					}, 800);
				}
			}
		}
	}
}
